import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';

class LYShimmer extends StatefulWidget {
  const LYShimmer({super.key});

  @override
  State<LYShimmer> createState() => _LYShimmerState();
}

class _LYShimmerState extends State<LYShimmer>
    with SingleTickerProviderStateMixin {
  late AnimationController controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller = AnimationController(
        vsync: this,
        value: 1,
        lowerBound: 1,
        upperBound: 2,
        duration: Duration(milliseconds: 300));

    // controller.addStatusListener((status) {
    //   if (status == AnimationStatus.completed) {
    //     controller.reset();
    //   }
    // });
    controller.forward(from: 1);
    controller.reverse(from: 2);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      color: Colors.blue,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          SizedBox(
            width: 200,
            height: 100,
            child: Shimmer.fromColors(
              baseColor: Colors.red,
              highlightColor: Colors.white,
              child: const Text(
                'Shimmer',
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 40.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          SizedBox(
            width: 200,
            height: 100,
            child: AnimatedBuilder(
              animation: controller,
              builder: (BuildContext context, Widget? child) {
                return Transform.scale(
                  scale: controller.value,
                  child: Image.asset(
                    'assets/images/home_1_r.png',
                    width: 60,
                    height: 60,
                  ),
                );
              },
            ),
          ),
          SizedBox(
            width: 200,
            height: 100,
            child: Shimmer(
                direction: ShimmerDirection.ttb,
                gradient:
                    LinearGradient(colors: [Color(0x09ffffff), Colors.white]),
                child: Text('sadasdasdsasd')),
          ),
        ],
      ),
    );
  }
}
